package com.yehongyu.mytools.basic.designpattern.observer;

import java.util.Observable;
import java.util.Observer;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class FrameObserver extends JFrame implements Observer {

	/**序列ID*/
	private static final long serialVersionUID = 1L;
	// 观察的数据
	int widthInfo = 0;
	int heightInfo = 0;
	JLabel jLabel1 = new JLabel("test1");
	JLabel jLabel2 = new JLabel();
	JLabel jLabel3 = new JLabel();
	JLabel jLabel4 = new JLabel();

	public FrameObserver() {
		super();
		this.add(jLabel1);
		this.add(jLabel2);
		this.add(jLabel3);
		this.add(jLabel4);
	}

	// 在update()方法中实现对数据的更新和其它必要的反应。
	public void update(Observable o, Object arg) {
		DateSubject subject = (DateSubject) o;
		widthInfo = subject.getWidthInfo();
		heightInfo = subject.getHeightInfo();
		jLabel1.setText("The heightInfo from subject is:  ");
		jLabel3.setText(String.valueOf(heightInfo));
		jLabel2.setText("The widthInfo from subject is:  ");
		jLabel4.setText(String.valueOf(widthInfo));
	}

}
